export const vaildatorRules = vm => {
  const rules = {
    sku: [
      {
        required: true,
        trigger: 'change',
        message: '请输入产品SKU',
      },
    ],
    name: [
      {
        required: true,
        trigger: 'change',
        message: '请输入产品名称',
      },
    ],
    en_name: [
      {
        required: true,
        trigger: 'change',
        message: '请输入产品名称en',
      },
    ],
    length: [
      {
        required: true,
        trigger: 'change',
        message: '请输入长度',
      },
    ],
    width: [
      {
        required: true,
        trigger: 'change',
        message: '请输入宽度',
      },
    ],
    height: [
      {
        required: true,
        trigger: 'change',
        message: '请输入高度',
      },
      {
        required: true,
        trigger: 'change',
        msgName: '请选择高度单位',
        validator: (rule, value, callback) => {
          const val = vm.infoModel.lwh_type
          if (!val) {
            callback(new Error(rule.msgName))
          } else {
            callback()
          }
        },
      },
    ],
    weight: [
      {
        required: true,
        trigger: 'change',
        message: '请输入重量',
      },
      {
        required: true,
        trigger: 'change',
        msgName: '请选择重量单位',
        validator: (rule, value, callback) => {
          const val = vm.infoModel.weight_type
          if (!val) {
            callback(new Error(rule.msgName))
          } else {
            callback()
          }
        },
      },
    ],
    is_battery: [
      {
        required: true,
        trigger: 'change',
        message: '请选择是否含电池',
      },
    ],
    is_liquid: [
      {
        required: true,
        trigger: 'change',
        message: '请选择是否带有液体',
      },
    ],

    is_magnetized: [
      {
        required: true,
        trigger: 'change',
        message: '请选择是否带磁',
      },
    ],
    goods_type: [
      {
        required: true,
        trigger: 'change',
        message: '请选择货物类型',
      },
    ],

    shops: [
      {
        required: true,
        trigger: 'change',
        validator: (rule, value, callback) => {
          const list = vm.infoModel.shops
          // const isExistence = vm.filterLevelChange(list, 'shop_sku')

          let flag = 0
          // let isId = 'no'
          for (const item of list) {
            if (!item.shop_sku) {
              flag = 1
              break
            } else if (!item.shop_code) {
              flag = 2
              break
            }
            //  else if (isExistence.includes(item.shop_sku)) {
            //   const arr = vm.shopsList.filter(e => e.value == item.shop_sku)
            //   isId = arr[0].label
            //   break
            // }
          }

          if (flag === 1) {
            callback(new Error('请输入平台'))
          } else if (flag == 2) {
            callback(new Error('请输入映射条形码'))
          } else {
            callback()
          }

          // else if (isId !== 'no') {
          //   callback(new Error(`${isId} 不能复选`))
          // }
        },
      },
    ],

    product_barcodes: [
      {
        required: true,
        trigger: 'change',
        validator: (rule, value, callback) => {
          const list = vm.infoModel.product_barcodes
          // const isExistence = vm.filterLevelChange(list, 'custom_code_name')
          let flag = 0
          // let isId = 'no'
          const { length } = list

          for (let i = 0; i < length; i++) {
            if (!list[i].custom_code_name) {
              flag = 1
              break
            } else if (!list[i].custom_code) {
              flag = 2
              break
            }
            //  else if (isExistence.includes(list[i].custom_code_name)) {
            //   const arr = vm.BarcodeNameList.filter(e => e.value == list[i].custom_code_name)
            //   isId = arr[0].label
            //   break
            // }
          }

          if (flag === 1) {
            callback(new Error('请输入条码名称'))
          } else if (flag == 2) {
            callback(new Error('请输入条形码'))
          } else {
            callback()
          }

          // else if (isId !== 'no') {
          //   callback(new Error(`${isId} 不能复选`))
          // }
        },
      },
    ],

    category_id: [
      {
        required: true,
        trigger: 'change',
        validator: (rule, value, callback) => {
          if (!value || !value.length) {
            callback(new Error('请选择产品品类'))
          } else {
            callback()
          }
        },
      },
    ],
  }
  return rules
}
